package com.love.driver.service.impl;

import java.util.List;
import com.love.common.core.utils.DateUtils;
import com.love.common.core.utils.snow.SnowflakeIdGenerator;
import com.love.driver.domain.LoveDriverOrder;
import com.love.driver.service.ILoveDriverOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.love.driver.mapper.LoveDriverRatingMapper;
import com.love.driver.domain.LoveDriverRating;
import com.love.driver.service.ILoveDriverRatingService;

/**
 * 代驾服务评价Service业务层处理
 * 
 * @author love
 * @date 2025-09-13
 */
@Service
public class LoveDriverRatingServiceImpl implements ILoveDriverRatingService 
{
    @Autowired
    private LoveDriverRatingMapper loveDriverRatingMapper;
    @Autowired
    private ILoveDriverOrderService loveDriverOrderService;
    //引用雪花算法
    private final SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator(2, 2);

    /**
     * 查询代驾服务评价
     * 
     * @param ratingId 代驾服务评价主键
     * @return 代驾服务评价
     */
    @Override
    public LoveDriverRating selectLoveDriverRatingByRatingId(Integer ratingId)
    {
        return loveDriverRatingMapper.selectLoveDriverRatingByRatingId(ratingId);
    }

    /**
     * 查询代驾服务评价列表
     * 
     * @param loveDriverRating 代驾服务评价
     * @return 代驾服务评价
     */
    @Override
    public List<LoveDriverRating> selectLoveDriverRatingList(LoveDriverRating loveDriverRating)
    {
        return loveDriverRatingMapper.selectLoveDriverRatingList(loveDriverRating);
    }

    /**
     * 新增代驾服务评价
     * 
     * @param loveDriverRating 代驾服务评价
     * @return 结果
     */
    @Override
    public int insertLoveDriverRating(LoveDriverRating loveDriverRating)
    {
        loveDriverRating.setRatingId(idGenerator.nextId());
        LoveDriverOrder loveDriverOrder = this.loveDriverOrderService.selectLoveDriverOrderByOrderId(loveDriverRating.getOrderId());
        if(loveDriverOrder!=null){
            loveDriverRating.setUserId(loveDriverOrder.getUserId());
            loveDriverRating.setDriverId(loveDriverOrder.getDriverId());
        }
        loveDriverRating.setCreateTime(DateUtils.getNowDate());
        return loveDriverRatingMapper.insertLoveDriverRating(loveDriverRating);
    }

    /**
     * 修改代驾服务评价
     * 
     * @param loveDriverRating 代驾服务评价
     * @return 结果
     */
    @Override
    public int updateLoveDriverRating(LoveDriverRating loveDriverRating)
    {
        return loveDriverRatingMapper.updateLoveDriverRating(loveDriverRating);
    }

    /**
     * 批量删除代驾服务评价
     * 
     * @param ratingIds 需要删除的代驾服务评价主键
     * @return 结果
     */
    @Override
    public int deleteLoveDriverRatingByRatingIds(Integer[] ratingIds)
    {
        return loveDriverRatingMapper.deleteLoveDriverRatingByRatingIds(ratingIds);
    }

    /**
     * 删除代驾服务评价信息
     * 
     * @param ratingId 代驾服务评价主键
     * @return 结果
     */
    @Override
    public int deleteLoveDriverRatingByRatingId(Integer ratingId)
    {
        return loveDriverRatingMapper.deleteLoveDriverRatingByRatingId(ratingId);
    }
}
